﻿<%@ Register TagPrefix="mwc" Namespace="MySoft.WebControls" Assembly="MySoft.WebControls" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Tj_AddWizard.aspx.vb"
    Inherits="Slxt.Tj_AddWizard" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>增加调价方案</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language="javascript" src="/_common/scripts/global.js"></script>
    <script language="javascript" src="/_controls/settings.aspx"></script>

    <link rel="stylesheet" type="text/css" href="/_forms/styles/form.css"/>
    <link href="/_common/styles/dialogs.css" type="text/css" rel="stylesheet"/>
    <link href="/_common/styles/global.css" type="text/css" rel="stylesheet"/>

    <script language="javascript" src="/_controls/util/util.js"></script>

    <script language="javascript" src="/_forms/FormBase.js"></script>

    <script language="javascript" src="/_controls/number/number.js"></script>

    <script language="javascript" src="/_controls/datetime/date.js"></script>

    <script language="javascript" src="/Slxt/js/Public.js"></script>

    <script language="javascript">

        function window.onload() {
            //加载调价房间列表
            frames("fraBldList").location.replace("Tj_AddWizard_RoomList.aspx?ProjGUID=" + crmForm.ProjGUID.value + "&funcid=01010111");

        }


        //第一步窗口 【下一步】按钮点击事件
        function btnNext1_onClick() {
            //1.校验必填
            crmForm.PlanName.value = Trim(crmForm.PlanName.value);
            if (crmForm.PlanName.value == "") {
                alert("请录入“调价方案”！");
                crmForm.PlanName.focus();
                return;
            }


            crmForm.ZdDate.value = Trim(crmForm.ZdDate.value);
            if (crmForm.ZdDate.value == "") {
                alert("请录入“制定日期”！");
                crmForm.ZdDate.focus();
                return;
            }

            crmForm.Remark.value = Trim(crmForm.Remark.value);

            //2.校验调价方案在本项目内是否重名：
            var sFile = "/Slxt/XMZB/Jggl_Pub_XMLHTTP.aspx?mode=1&ProjGUID=" + escape(crmForm.ProjGUID.value);
            sFile += "&PlanName=" + escape(crmForm.PlanName.value);

            var strReturn = openXMLHTTP(sFile, "PLNAME_VAILD");
            if (strReturn != undefined && strReturn != "") {
                if (strReturn != "OK") {
                    alert(strReturn);
                    return;
                }
            }
            else {
                return;
            }


            //3.校验调价楼栋列表
            var oBld = frames("fraBldList");
            if (oBld.document.readyState === "complete") {
                if (oBld.DataValid() == false) {
                    return;
                }
                //4.切换到第二步窗口
                div1.style.display = "none";
                div2.style.display = "";
                div3.style.display = "none";
            }
            else {
                alert("调价房间列表未加载完成，请稍后操作！");
                return;
            }

        }

        //校验是否有记录
        function DataValid() {
            var tblRoomList = document.getElementById("gridBar");
            if (tblRoomList && tblRoomList.tBodies[0].rows.length === 0) {
                alert("请选择调价房间！");
                return false;
            }
            return true;
        }

        //第二步窗口 【下一步】按钮点击事件
        function btnNext2_onClick() {

            //mode0:重新定价.
            if (crmForm.rblMode0.checked ) {
                //校验页面数据有效性
                if (PlanVaild() == true) {
                    div1.style.display = "none";
                    div2.style.display = "none";
                    div3.style.display = "";
                    var frmEq = frames("fraEq");
                    if (frmEq.location.toString() === "about:blank" || frmEq.location.toString() === "") {
                        //取因素项
                        frmEq.location.replace("Tj_Add_Equation.aspx?ProjGUID=" + crmForm.ProjGUID.value + "&funcid=01010111");
                    }
                }
                else {
                    return;
                }
            } else {
                //保存调价方案
                var strGuid = SavePlan();
                if (strGuid != undefined && strGuid != "") {
                    //保存调价房间
                    var oBld = frames("fraBldList");
                    oBld.document.all("PlanGUID").value = strGuid;
                    if (crmForm.rblMode1.checked) {
                        parent.returnValue = "mode1|" + strGuid;
                    } else {
                        parent.returnValue = "mode3|" + strGuid;
                    }
                    parent.close();
                }
                else {
                    return false;
                }
            }

            //mode2:从外部文件导入价格
            if (crmForm.rblMode2.checked == true) {
                alert("暂时还不支持导入价格，二期实现！");
                return false;
            }

        }

        //第二步窗口【上一步】按钮点击事件
        function btnPre2_onClick() {
            div1.style.display = '';
            div2.style.display = 'none';
            div3.style.display = 'none';
        }

        //第三步窗口【上一步】按钮点击事件
        function btnPre3_onClick() {
            div1.style.display = 'none';
            div2.style.display = '';
            div3.style.display = 'none';
        }

        //第三步窗口 【确定】按钮点击事件
        function btnNext3_onClick() {

            //1.校验调价因素列表是否有效（必须有数据）;
            var oEq = frames("fraEq");
            if (oEq.document.readyState === "complete") {

                var arrReturn = oEq.DataVaild();
                if (arrReturn == undefined || arrReturn == null || arrReturn == "") return false;

                //保存调价方案, 调价房间
                var strGuid = SavePlan(arrReturn);
                if (strGuid !== "") {

                    parent.returnValue = "mode0|" + strGuid;
                    parent.close();
                }
                else {
                    return false;
                }
            }
            else {
                alert("调价房间列表未加载完成，请稍后操作！");
                return;
            }

        }

        //校验第二步窗口（确定调整方式）录入内容是否有效
        function PlanVaild() {
            //mode0:重新定价.
            if (crmForm.rblMode0.checked) {
                //校验计算方法及值必填
                if (crmForm.radZj.checked)	        //总价
                {
                    var txtBaseTotal = crmForm.BaseTotal;
                    var sBase = txtBaseTotal.value.replace(/,/g, "");
                    if (sBase == "") {
                        alert("请录入“总价”！");
                        txtBaseTotal.focus();
                        return false;
                    }

                    if (sBase <= 0) {
                        alert("“总价”项中的值必须大于0！");
                        txtBaseTotal.focus();
                        return false;
                    }

                }
                else								//基点单价
                {
                    var txtBasePrice = crmForm.BasePrice;
                    var sBase = txtBasePrice.value.replace(/,/g, "");
                    if (sBase == "") {
                        alert("请录入“基点单价”！");
                        txtBasePrice.focus();
                        return false;
                    }

                    if (sBase <= 0) {
                        alert("“基点单价”项中的值必须大于0！");
                        txtBasePrice.focus();
                        return false;
                    }
                }

                return true;
            }
            else {
                return true;
            }
        }

        //保存方案
        function SavePlan(arrReturn) {

            var BUGUID = crmForm.BUGUID.value;
            var ProjGUID = crmForm.ProjGUID.value;
            var PlanName = crmForm.PlanName.value;
            var ZdDate = crmForm.ZdDate.value;

            var PriceTuneMode = 0;
            if (crmForm.rblMode0.checked) {
                PriceTuneMode = 0;
            }
            else if (crmForm.rblMode1.checked) {
                PriceTuneMode = 1;
            }
            else {
                PriceTuneMode = 2;
            }

            var DjArea = "";
            if (crmForm.rblDjArea_0.checked) {
                DjArea = "建筑面积";
            } else {
                DjArea = "套内面积";
            }

            var CalType = "";
            if (crmForm.radZj.checked) {
                CalType = "总价";
            }else{
                CalType = "单价";
            }

            var BaseTotal = (crmForm.BaseTotal.value).replace(/,/g, "");
            if (!BaseTotal) {
                BaseTotal = "0";
            }
            var BasePrice = (crmForm.BasePrice.value).replace(/,/g, "");
            if (!BasePrice) {
                BasePrice = "0";
            }

            var Remark = crmForm.Remark.value;

            var aryPlanXml = [];
            aryPlanXml.push("<myData>");
            //收集底价调价方案信息
            aryPlanXml.push("<s_TjPlan keyname='PlanGUID' keyvalue=''>");
            aryPlanXml.push("<BUGUID>" + BUGUID + "</BUGUID>");
            aryPlanXml.push("<ProjGUID>" + ProjGUID + "</ProjGUID>");
            aryPlanXml.push("<PlanName>" + PlanName + "</PlanName>");
            aryPlanXml.push("<ZdDate>" + ZdDate + "</ZdDate>");
            aryPlanXml.push("<PriceTuneMode>" + PriceTuneMode + "</PriceTuneMode>");
            aryPlanXml.push("<DjArea>" + DjArea + "</DjArea>");
            aryPlanXml.push("<CalType>" + CalType + "</CalType>");
            aryPlanXml.push("<BaseTotal>" + BaseTotal + "</BaseTotal>");
            aryPlanXml.push("<BasePrice>" + BasePrice + "</BasePrice>");
            aryPlanXml.push("<Remark>" + Remark + "</Remark>");
            aryPlanXml.push("<Status>待审批</Status>");
            aryPlanXml.push("</s_TjPlan>");

            //得到调价房间列表信息
            var strRoomXml = frames("fraBldList").getRoomXml();
            aryPlanXml.push(strRoomXml);
            

            //如果是重新定价则收集调价因素XML
            if (PriceTuneMode === 0) {
                var sEqXml = frames("fraEq").getEqXml(arrReturn);
                aryPlanXml.push(sEqXml);
            }
            aryPlanXml.push("</myData>");
            //得到调价房间信息
            var sUrl = "Jggl_Pub_XMLHTTP.aspx";
            strReturn = openXMLHTTP(sUrl, "PLAN_SAVE", aryPlanXml.join(""));
            if (strReturn === "EQ_ERROR") {
                alert("因素定义保存失败！");
                return "";
            } else if (strReturn !== "") {
                return strReturn;
            } else {
                alert("保存调价方案失败！");
                return "";
            }

        }

        //点击调价方式
        function rblTjFs_Click() {
            if (crmForm.rblMode0.checked == false) {
                crmForm.BaseTotal.value = "";
                crmForm.BasePrice.value = "";
                crmForm.BaseTotal.setReadOnly(true);
                crmForm.BasePrice.setReadOnly(true);
                document.all("btnNext2").innerText = "确 定";
            }
            else {
                document.all("btnNext2").innerText = "下一步";
                if (crmForm.radZj.checked == true) {
                    crmForm.BaseTotal.setReadOnly(false);
                    crmForm.BasePrice.setReadOnly(true);
                    crmForm.BasePrice.value = "";
                }
                else {
                    crmForm.BaseTotal.setReadOnly(true);
                    crmForm.BaseTotal.value = "";
                    crmForm.BasePrice.setReadOnly(false);
                }
            }
        }
    </script>

</head>
<body ms_positioning="GridLayout">
    <form class="map" id="crmForm" method="post" runat="server">
    <asp:TextBox ID="ProjGUID" Style="display: none" runat="server"></asp:TextBox>
    <asp:TextBox ID="BUGUID" Style="display: none" runat="server"></asp:TextBox>
    <div id="div1">
        <table height="100%" cellspacing="0" cellpadding="0" width="100%">
            <tr>
                <td class="header">
                    <div class="header">
                        增加调价方案</div>
                    <br>
                    <span style="padding-left: 8px">第一步：新增方案，确定范围</span>
                </td>
            </tr>
            <tr>
                <td class="main">
                    <table style="table-layout: fixed; vertical-align: text-bottom" height="100%" cellspacing="0"
                        cellpadding="0" width="100%">
                        <colgroup>
                            <col width="60">
                            <col>
                            <col style="padding-left: 20px" width="80">
                            <col>
                        </colgroup>
                        <tr height="4">
                            <td colspan="4">
                            </td>
                        </tr>
                        <tr height="25">
                            <td class="req">
                                调价方案
                            </td>
                            <td>
                                <asp:TextBox ID="PlanName" runat="server" MaxLength="100" req="1" forbiddenChars="@%#?-|,_;'&quot;&amp;&lt;&gt;~$[]"></asp:TextBox>
                            </td>
                            <td class="req">
                                制定日期
                            </td>
                            <td>
                                <table style="table-layout: fixed" cellspacing="0" cellpadding="0" width="100%">
                                    <colgroup>
                                        <col>
                                        <col width="40">
                                    </colgroup>
                                    <tr>
                                        <td>
                                            <asp:TextBox class="dtm" ID="ZdDate" runat="server" mapType="dtm" time="0" returnValue=""></asp:TextBox>
                                        </td>
                                        <td style="padding-left: 4px">
                                            <img class="dtm" src="/_imgs/btn_off_cal.gif">
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr height="25">
                            <td>
                                计价方式
                            </td>
                            <td colspan="3">
                                <asp:RadioButtonList ID="rblDjArea" runat="server" Width="200px" RepeatDirection="Horizontal">
                                    <asp:ListItem Value="建筑面积" Selected="True">建筑面积</asp:ListItem>
                                    <asp:ListItem Value="套内面积">套内面积</asp:ListItem>
                                </asp:RadioButtonList>
                            </td>
                        </tr>
                        <tr height="60">
                            <td style="vertical-align: top; padding-top: 5px">
                                调价说明
                            </td>
                            <td colspan="3">
                                <textarea id="Remark" rows="3" runat="server"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <iframe id="fraBldList" src="" frameborder="no" width="100%" scrolling="no" height="100%">
                                </iframe>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="40">
                <td class="buttons">
                    <table style="table-layout: fixed; width: 100%; height: 100%" cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="right">
                                <button style="width: 70px" onclick="btnNext1_onClick();" name="btnNext1" type="button">
                                    下一步</button>&nbsp;&nbsp;
                                <button style="width: 65px" onclick="parent.window.close();" name="btnClose" type="button"
                                        value="取 消">
                                        取 消</button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="10">
                <td>
                </td>
            </tr>
        </table>
    </div>
    <div id="div2" style="display: none">
        <table height="100%" cellspacing="0" cellpadding="0" width="100%">
            <tr>
                <td class="header">
                    <div class="header">
                        增加调价方案</div>
                    <br>
                    <span style="padding-left: 8px">第二步：确认价格调整方式</span>
                </td>
            </tr>
            <tr>
                <td class="main">
                    <table style="table-layout: fixed" height="100%" cellspacing="0" cellpadding="0"
                        width="100%">
                        <tr height="5">
                            <td>
                            </td>
                        </tr>
                        <tr height="25">
                            <td>
                                <asp:RadioButton ID="rblMode0" onclick="rblTjFs_Click()" runat="server" Checked="True"
                                    GroupName="aa" Text="重新定标准价"></asp:RadioButton>
                            </td>
                        </tr>
                        <tr height="50">
                            <td>
                                <table style="table-layout: fixed; vertical-align: text-bottom" height="100%" cellspacing="0">
                                    <colgroup>
                                        <col style="padding-left: 10px" width="80">
                                        <col width="80">
                                        <col width="80">
                                        <col style="padding-left: 5px">
                                    </colgroup>
                                    <tr height="25">
                                        <td>
                                            计算方法
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="radZj" onclick="rblTjFs_Click()" runat="server" Checked="True"
                                                GroupName="bb" Text="总价"></asp:RadioButton>
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" CssClass="num" ID="BaseTotal" returnValue="0" min="0"
                                                max="100000000" grp="true" acc="2" dt=""></asp:TextBox>
                                        </td>
                                        <td>
                                            万元
                                        </td>
                                    </tr>
                                    <tr height="25">
                                        <td>
                                        </td>
                                        <td>
                                            <asp:RadioButton ID="radDj" runat="server" Text="基点单价" GroupName="bb" onclick="rblTjFs_Click()">
                                            </asp:RadioButton>
                                        </td>
                                        <td>
                                            <asp:TextBox runat="server" CssClass="num" ReadOnly ID="BasePrice" returnValue="0"
                                                min="0" max="100000000" grp="true" acc="2" dt=""></asp:TextBox>
                                        </td>
                                        <td>
                                            元
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr height="25" runat="server" id="trDjEnabled">
                            <td>
                                <asp:RadioButton ID="rblMode3" runat="server" Text="在底价基础上定价" GroupName="aa" onclick="rblTjFs_Click()">
                                </asp:RadioButton>
                            </td>
                        </tr>
                        <tr height="25">
                            <td>
                                <asp:RadioButton ID="rblMode1" runat="server" Text="在原标准价格基础上调整" GroupName="aa" onclick="rblTjFs_Click()">
                                </asp:RadioButton>
                            </td>
                        </tr>
                        <tr height="25">
                            <td>
                                <asp:RadioButton ID="rblMode2" runat="server" Text="从外部文件导入价格（Excel）" GroupName="aa"
                                    onclick="rblTjFs_Click()" Style="display: none"></asp:RadioButton>
                            </td>
                        </tr>
                        <tr>
                            <td>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="40">
                <td class="buttons">
                    <table style="table-layout: fixed; width: 100%; height: 100%" cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="right">
                                <button style="width: 70px" onclick="btnPre2_onClick();" name="btnPre2" type="button">
                                    上一步</button>
                            </td>
                            <td align="right">
                                <button style="width: 70px" onclick="btnNext2_onClick();" name="btnNext2" type="button">
                                    下一步</button>
                                &nbsp;&nbsp;
                                <button style="width: 70px" onclick="parent.window.close();" name="btnClose" type="button">
                                    取 消</button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="10">
                <td>
                </td>
            </tr>
        </table>
    </div>
    <div id="div3" style="display: none">
        <table height="100%" cellspacing="0" cellpadding="0" width="100%">
            <tr>
                <td class="header">
                    <div class="header">
                        增加调价方案</div>
                    <br>
                    <span style="padding-left: 8px">第三步：确定调价因素</span>
                </td>
            </tr>
            <tr>
                <td class="main">
                    <table style="table-layout: fixed; vertical-align: text-bottom" height="100%" cellspacing="0"
                        cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <iframe id="fraEq" src="" frameborder="no" height="100%" width="100%" scrolling="no">
                                </iframe>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="40">
                <td class="buttons">
                    <table style="table-layout: fixed; width: 100%; height: 100%" cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="right">
                                <button style="width: 70px" onclick="btnPre3_onClick();" name="btnPre3" type="button">
                                    上一步</button>
                            </td>
                            <td align="right">
                                <button style="width: 70px" onclick="btnNext3_onClick();" name="btnNext3" type="button">
                                    确 定</button>
                                &nbsp;&nbsp;
                                <button style="width: 70px" onclick="parent.window.close();" name="btnClose" type="button">
                                    取 消</button>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr height="10">
                <td>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
